package cn.sixmillions.now;

import cn.sixmillions.domain.Student;
import cn.sixmillions.mb.io.Resources;
import cn.sixmillions.mb.sqlSession.SqlSession;
import cn.sixmillions.mb.sqlSession.SqlSessionFactory;
import cn.sixmillions.mb.sqlSession.SqlSessionFactoryBuilder;
import com.alibaba.fastjson.JSON;

import java.io.InputStream;
import java.util.List;

/**
 * 测试自己实现的mybatis，相当于在我们项目引入mybatis
 *
 * @author sixmillions
 */
public class MbTest {

    public static void main(String[] args) throws Exception {
        //读取配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        //解析配置文件
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //参数
        Student studentParams = new Student();
        studentParams.setStudentId(666);
        studentParams.setStudentName("sixmillions");
        //查询单个
        Student student = sqlSession.selectOne("student.selectOne", studentParams);
        System.out.println(JSON.toJSONString(student));
        //查询所有
        List<Student> students = sqlSession.selectList("student.selectList");
        System.out.println(JSON.toJSONString(students));
    }

}
